/*
 * @Description: 起飞点 type = 7
 * @Date: 2022-03-31 17:22:09
 * @Author: yeming
 */
import { fromLonLat } from 'ol/proj.js'
import { Point } from '../model/point.js'
import { removeFeatureAndDeleteHashMap, removeAllFeatureAndDeleteHashMap } from '../common/removeFeature.js'

const AIRLINE_TAKE_OFF = './static/olcsMap/img/takeoff.png'

class TakeOffPoint {
  constructor(ol2d, hashMap, vectorSource) {
    this.ol2d = ol2d
    this.hashMap = hashMap
    this.vectorSource = vectorSource
  }

  /**
   * @desc: 添加起飞点(olcs rend3d = true 同步处理，暂不添加3d Entity)
   * @param {Number} sessionId
   * @param {Array} latlng
   */
  addTakeOffPoint (sessionId, latlng, image) {
    image = image != '' && image ? image : AIRLINE_TAKE_OFF

    let currentPointMap = this.hashMap.get(sessionId)
    if (currentPointMap == undefined) {
      let point = new Point(this.ol2d, this.vectorSource)
      point.addSinglePoint(sessionId, latlng, 7, 0, image, false, null, true)
      this.hashMap.set(sessionId, { 'item2d': point, 'item3d': null }) // 已做3d同步 rend3d = true item3d = null
    } else {
      this.updateTakeOffPointPosition(sessionId, latlng)
    }
  }

  /**
   * @desc: 更新起飞点
   * @param {Number} sessionId
   * @param {Array} latlng
   */
  updateTakeOffPointPosition (sessionId, latlng) {
    let currentPoint = this.hashMap.get(sessionId).item2d
    // 2d点
    let coordinate = fromLonLat(latlng)
    let feature = currentPoint.feature
    if (feature != null) feature.getGeometry().setCoordinates(coordinate)
    // 3d
    // let currentPoint3d = this.hashMap.get(sessionId).item3d
    // let position = new Cesium.Cartesian3.fromDegrees(latlng[0], latlng[1], latlng[2] || 80)
    // currentPoint3d.position = position
  }

  /**
   * @desc: 删除起飞点
   * @param {Number} sessionId
   */
  delTakeOffPoint (sessionId) {
    removeFeatureAndDeleteHashMap(sessionId, this.hashMap, this.vectorSource)
  }

  /**
   * @desc: 删除所有起飞点
   */
  delAllTakeOffPoint () {
    removeAllFeatureAndDeleteHashMap(this.hashMap, this.vectorSource)
  }
}

export default TakeOffPoint
